<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Ping 数据库连接</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.pg-ping" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">pg_ping</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">pg_ping</span> &mdash; <span class="dc-title">Ping 数据库连接</span></p>

   </div>
   <div class="refsect1 unknown-seealsp" id="refsect1-function.pg-ping-unknown-seealsp">
    <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>pg_ping</strong></span>
       ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span>
      ) : <span class="type">bool</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>pg_ping()</strong></span> ping
     数据库连接，如果中断则尝试重新连接。如果连接在活动状态返回
     <strong><code>TRUE</code></strong>，否则返回 <strong><code>FALSE</code></strong>。
    </p>
    <p class="para">
     <div class="example" id="example-2509">
      <p><strong>Example #1 <span class="function"><strong>pg_ping()</strong></span></strong></p>
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_pconnect&nbsp;</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"An&nbsp;error&nbsp;occured.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br />if&nbsp;(!</span><span style="color: #0000BB">pg_ping</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">))<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">"Connection&nbsp;is&nbsp;broken\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
      </div>

     </div>
     参见 <span class="function"><a href="pg_connection_status.html" class="function">pg_connection_status()</a></span> 和
    <span class="function"><a href="pg_connection_reset.html" class="function">pg_connection_reset()</a></span>。
    </p>
   </div>

  </div></div></div></body></html>